<?php
/**
 * app更新
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/3/7
 * Time: 15:39
 */
class LogdatauploadController extends Yaf_Controller_Abstract
{
    function IndexAction()
    {
        $request = $this->getRequest();
        $data = $request->getPost("data","");
        $yiyuan_id = $request->getPost("yiyuan_id","");
        $user_department_id = $request->getPost("user_department_id",0);
        //$data = strip_tags($_REQUEST['data']);
        //$yiyuan_id = strip_tags($_REQUEST['yiyuan_id']);
        //$user_department_id = strip_tags($_REQUEST['user_department_id']);
        if($data == "")
        {
            Utility::apiJsonError(20020, '数据不能为空！');
        }
        if($yiyuan_id === "" )
        {
            Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }
        if(Yaconf::get("config$yiyuan_id.fenbiao_state") == "true")
        {
            $log_record = "log_record_".$user_department_id;
        }
        else
        {
            $log_record = "log_record";
        }


        // 解压缩数据
        /*是否开启压缩 默认开启*/
        $compression_http_data = $_REQUEST['compression_http_data'];
        // 解压缩数据
        $data = Utility::uncompress($data,$compression_http_data);
        //$data = $LogRecordModel->uncompress($data,$_REQUEST["compression_http_data"]);

        $upload_data = json_decode($data,true);
        //print_r($upload_data);exit;
        foreach($upload_data as $one)
        {
            $insert_data[] = array(
                'login_user_id' => $one['login_user_id'],
                'login_depart_id' => $one['login_depart_id'],
                'function_name' => $one['function_name'],
                'http_state_code' => $one['http_state_code'],
                'use_time' => $one['use_time'],//TODO
                'message' => $one['message'],
                'record_time' => $one['record_time'],
                'shebei_id' => $one['shebei_id'],
                'yiyuan_id' => $yiyuan_id
            );
           // $sql_act = $LogRecordModel->add($log_record,$insert_data);
        }
        $sql_act = Utility::multiInsert($log_record,$insert_data);
        if(is_array($sql_act)&&count($sql_act)>0)
        {
            $statr = array(
                'state' =>'ok',
            );
            //$this->apiLog(strlen(json_encode($_REQUEST)));
            $res["msg"] = "";
            $res["error"] = 200;
            Utility::apiJsonResultExtends($res);
            //Utility::apiJsonResult($statr,"",$_REQUEST["compression_http_data"]);
        }else
        {
            Utility::apiJsonError(20013, '操作失败！');
        }
    }
}